﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gollie.Mail;
using NLog;

namespace Gollie.Mail.Queue.Service
{
	public class MailService : IMailService
	{
		private static readonly Logger logger = LogManager.GetCurrentClassLogger();

		public void Queue(EMail email)
		{
			email.DoQueue();
		}

		public void QueueAsync(EMail email)
		{
			if (MainTask.QueueAsync(email) == false)
			{
				logger.Warn("Queueing mail async failed. Queueing synced...");
				this.Queue(email);
			}
		}

		public void QueueCollection(EMailCollection emails)
		{
			emails.DoQueue();
		}

		public void QueueCollectionAsync(EMailCollection emails)
		{
			if (MainTask.QueueAsync(emails) == false)
			{
				logger.Warn("Queueing mailcollection async failed. Queueing synced...");
				this.QueueCollection(emails);
			}
		}

		public void QueueBulk(BulkMail emails)
		{
			emails.DoQueue();
		}

		public void QueueBulkAsync(BulkMail emails)
		{
			if (MainTask.QueueAsync(emails) == false)
			{
				logger.Warn("Queueing bulkmail async failed. Queueing synced...");
				this.QueueBulk(emails);
			}
		}
	}
}
